package com.chenxinzhimusic.service

import kotlinx.coroutines.Job
import kotlin.coroutines.cancellation.CancellationException

object DownloadManager {
    private val jobs = mutableMapOf<String, Job>()

    fun addJob(key: String, job: Job) {
        jobs[key] = job
    }

    fun pause(key: String) {
        jobs[key]?.cancel(CancellationException("Paused"))
    }

    fun cancel(key: String) {
        jobs[key]?.cancel(CancellationException("Canceled"))
        jobs.remove(key)
    }

    fun isRunning(key: String): Boolean {
        return jobs[key]?.isActive == true
    }
}